#############################################################################
# Calculate ANDE for m=5 multiply imputed data sets.

ANDE.1 <- ANDE.fun(m.comp.1, y.comp.1)
ANDE.2 <- ANDE.fun(m.comp.2, y.comp.2)
ANDE.3 <- ANDE.fun(m.comp.3, y.comp.3)
ANDE.4 <- ANDE.fun(m.comp.4, y.comp.4)
ANDE.5 <- ANDE.fun(m.comp.5, y.comp.5)

c.1 <- apply(ANDE.1, 2, mean)
c.2 <- apply(ANDE.2, 2, mean)
c.3 <- apply(ANDE.3, 2, mean)
c.4 <- apply(ANDE.4, 2, mean)
c.5 <- apply(ANDE.5, 2, mean)

s.1 <- apply(ANDE.1, 2, sd)
s.2 <- apply(ANDE.2, 2, sd)
s.3 <- apply(ANDE.3, 2, sd)
s.4 <- apply(ANDE.4, 2, sd)
s.5 <- apply(ANDE.5, 2, sd)

coefs <- cbind(c.1, c.2, c.3, c.4, c.5)
c.combined <- apply(coefs, 1, mean)

var.within <- cbind(s.1^2, s.2^2, s.3^2, s.4^2, s.5^2)
var.within <- apply(var.within, 1, mean)

m <- 5
var.between <- (coefs - c.combined)^2
var.between <-  apply(var.between, 1, sum)
var.between <-  (m-1)^-1 * var.between

s.combined <- sqrt(var.within + (1 + m^-1) * var.between )

combined.res <- cbind(c.combined, s.combined)
combined.res <- round(combined.res, 2)

rownames(combined.res) <-c("restrictive", "liberal", "average")

res.ANDE <- combined.res[1,1]
res.ANDE.se <- combined.res[1,2]

lib.ANDE <- combined.res[2,1]
lib.ANDE.se <- combined.res[2,2]

av.ANDE <- combined.res[3,1]
av.ANDE.se <- combined.res[3,2]

